package com.jyz.until;

import com.jyz.mapper.PermissionMapper;
import com.jyz.pojo.Permission;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.List;

public class PermissionMapperTest {
    SqlSession session;
    PermissionMapper mapper;

    @Before
    public void before() {
        //1、创建SqlSessionFactory对象，也是单例模式的
        SqlSessionFactory factory = MyBatisUtil.getSqlSessionFactory();
        //2、创建SqlSession对象 true 自动提交事务 不写也没事 因为默认在sqlsession关闭时提交事务
        session = factory.openSession(true);
        //3、调用session的方法namespace的名字.id
        mapper = session.getMapper(PermissionMapper.class);

    }

    @After
    public void after() {
        //5、关闭资源
        session.close();
    }

    @Test
    public void selectRole_Permission() {
//        List<Permission> permissions = mapper.selectAll();
//        System.out.println("permissions = " + permissions);
        List<Permission> permissions = mapper.selectByRid(1);
        System.out.println("permissions = " + permissions);
    }

}